<?php
// File and new size
if (isset($_POST['filename'])) {
$filename = $_POST['filename'];

// Content type
header('Content-type: image/jpeg');
list($width, $height) = getimagesize($filename);
list($newwidth,$newheight) = split("x",$_POST['size'],2);
$thumb = imagecreatetruecolor($newwidth, $newheight);
$source = imagecreatefromjpeg($filename);

if ($_POST['function']=="resize") {

// Resize
imagecopyresized($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
} else {
	ImageCopyMerge($thumb,$source,0,0,0,0,$newwidth,$newheight,100);
}

// Output
imagejpeg($thumb);
}
?> 
